package birs.controller.staff;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import birs.controller.staff.task.STF003Task;
import birs.util.ConnectionDB;

/**
 * Servlet implementation class StaffReward
 */
@WebServlet("/STF003Controller")
public class STF003Controller extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public STF003Controller() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			process(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			process(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	private void process(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException{
		try (Connection misCon = ConnectionDB.getMisConnection()){
			STF003Task staffRewardTask = new STF003Task(misCon);
			if(request.getParameter("criteria")==null){
				staffRewardTask.getStaffReward(request, response);
			}else if(request.getParameter("criteria").equalsIgnoreCase("rewardId")){
				staffRewardTask.getDrilldownByReward(request, response, request.getParameter("p1"));
			}else if(request.getParameter("criteria").equalsIgnoreCase("staffId")){
				staffRewardTask.getSecondDrilldown(request, response, request.getParameter("p1"));
			}
		}
	}
}
